package cn.jon.androidbanneranimation

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {

    private lateinit var autoScrollRecyclerView: InfiniteAutoScrollRecyclerView
    private lateinit var adapter: SampleAdapter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        setupAutoScrollRecyclerView()
    }

    private fun setupAutoScrollRecyclerView() {
        autoScrollRecyclerView = findViewById(R.id.autoScrollRecyclerView)

        // 配置参数
        autoScrollRecyclerView.apply {
            autoScrollInterval = 3000L // 3秒自动滚动一次，便于观察动画
            pauseAfterUserInteraction = 2000L // 用户操作后2秒恢复
            itemScaleFactor = 2.0f // 放大到2倍宽度，120dp变成240dp
            animationDuration = 600L // 动画持续600ms，便于观察
            enableInfiniteScroll = true // 循环滚动
            autoScrollStartDelay = 0L // 设置为0立刻开始，或1000L表示1秒后开始
        }

        // 准备数据
        val sampleData = listOf(
            SampleItem(android.R.drawable.ic_menu_camera, "相机", "这是相机功能"),
            SampleItem(android.R.drawable.ic_menu_gallery, "图库", "这是图库功能"),
            SampleItem(android.R.drawable.ic_menu_manage, "管理", "这是管理功能"),
            SampleItem(android.R.drawable.ic_menu_share, "分享", "这是分享功能"),
            SampleItem(android.R.drawable.ic_menu_send, "发送", "这是发送功能"),
            SampleItem(android.R.drawable.ic_menu_info_details, "详情", "这是详情功能")
        )

        // 设置适配器
        adapter = SampleAdapter(sampleData)
        autoScrollRecyclerView.adapter = adapter
    }

    override fun onResume() {
        super.onResume()
        autoScrollRecyclerView.resumeAutoScroll()
    }

    override fun onPause() {
        super.onPause()
        autoScrollRecyclerView.pauseAutoScroll()
    }
}